package com.y.architecture.location;

import android.content.Context;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationListener;

import rx.Observable;
import rx.Subscriber;

/**
 * Created by youjingjing on 2017/11/22.
 */

public class LocationOnSubscribe implements Observable.OnSubscribe<AMapLocation>{
    private final Context context;

    public LocationOnSubscribe(Context context) {
        this.context = context;
    }

    @Override
    public void call(final Subscriber<? super AMapLocation> subscriber) {
        AMapLocationListener bdLocationListener = new AMapLocationListener(){

            @Override
            public void onLocationChanged(AMapLocation aMapLocation) {
                subscriber.onNext(aMapLocation);
                subscriber.onCompleted();
            }
        };
        LocationClient.get(context).locate(bdLocationListener);
}
}
